Skip to content

Comments

Fix push_to_pull_request_branch generating bad patch on follow-up issue_comment runs#17206

Closed
Copilot wants to merge 14 commits intomainfrom
copilot/recreate-pr-16927-cleanly
Closed

Fix push_to_pull_request_branch generating bad patch on follow-up issue_comment runs#17206
Copilot wants to merge 14 commits intomainfrom
copilot/recreate-pr-16927-cleanly

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

  • Refactor generate_git_patch.cjs: add resolveBaseRef, writePatch, tryBranchStrategy, tryHeadStrategy helpers; fetch origin/ before falling back to merge-base; add core.info/core.warning logging
  • Update generate_git_patch.test.cjs: add global.core mock before tests and vi.clearAllMocks() in beforeEach
  • Update safe_outputs_handlers.test.cjs: add global.core mock and vi.clearAllMocks()
  • Delete actions/setup/sh/generate_git_patch.sh
  • Delete pkg/workflow/git_patch_head_test.go
  • Update actions/setup/README.md: change shell scripts count from 7 to 6, remove generate_git_patch.sh entry
  • Add actions/setup/js/shim.cjs — minimal global.core shim (no-op in GitHub Actions, console-backed in standalone Node.js)
  • Load shim first in safe-outputs-mcp-server.cjs
  • Load shim first in safe_inputs_mcp_server_http.cjs
  • Add shim.cjs to SAFE_INPUTS_FILES and SAFE_OUTPUTS_FILES in setup.sh
  • Fix TypeScript errors in shim.cjs: add @ts-expect-error on global.core references
Original prompt

Recreate this PR #16927 cleanly.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Changeset

  • Type: patch
  • Description: Fetches the missing origin/(branch) ref before generating the push_to_pull_request_branch patch so only new commits land on follow-up issue_comment runs.

Generated by Changeset Generator



✨ PR Review Safe Output Test - Run 22230889913

💥 [THE END] — Illustrated by Smoke Claude


Changeset

  • Type: patch
  • Description: Fetches the missing origin/(branch) ref before generating the push_to_pull_request_branch patch so follow-up issue_comment runs only include new commits.

Generated by Changeset Generator



✨ PR Review Safe Output Test - Run 22232216256

💥 [THE END] — Illustrated by Smoke Claude


Changeset

  • Type: patch
  • Description: Fetches the missing origin/(branch) ref before generating the push_to_pull_request_branch patch so follow-up issue_comment runs only include new commits.

Generated by Changeset Generator



✨ PR Review Safe Output Test - Run 22233329042

💥 [THE END] — Illustrated by Smoke Claude

… follow-up runs

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Recreate pull request 16927 cleanly Fix push_to_pull_request_branch generating bad patch on follow-up issue_comment runs Feb 20, 2026
Copilot AI requested a review from pelikhan February 20, 2026 15:50
@pelikhan pelikhan added the smoke label Feb 20, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 20, 2026

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

@github-actions
Copy link
Contributor

🧪 Smoke Project is now testing project operations...

@github-actions
Copy link
Contributor

🧪 Smoke Temporary ID is now testing temporary ID functionality...

@github-actions
Copy link
Contributor

📰 BREAKING: Smoke Copilot is now investigating this pull request. Sources say the story is developing...

@github-actions
Copy link
Contributor

github-actions bot commented Feb 20, 2026

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

@github-actions
Copy link
Contributor

Smoke Project completed successfully. All project operations validated.

@github-actions
Copy link
Contributor

Smoke test (Codex) summary:
PRs: fix: supply chain and shell injection security findings | Delete shared/mood.md workflow and clean up all references
GitHub MCP: ✅
Serena MCP: ✅
Playwright: ✅
File write/read: ✅
Build: ✅
Overall: PASS

🔮 The oracle has spoken through Smoke Codex for issue #17206

@github-actions
Copy link
Contributor

Smoke test results for PR #17206:

Test
GitHub MCP
Safe Inputs GH CLI
Serena MCP
Playwright
File Write/Read
Discussion
Build
Discussion Create
Haiku Dispatch
PR Review

Overall: PASS (10/11 - Serena MCP tools unavailable)

@pelikhan @Copilot

📰 BREAKING: Report filed by Smoke Copilot for issue #17206

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smoke test review: PR looks good. README docs are kept in sync with file removals, and the generate_git_patch.cjs refactoring is well-structured with clear strategy separation.

📰 BREAKING: Report filed by Smoke Copilot for issue #17206

@github-actions
Copy link
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions
Copy link
Contributor

Smoke Test Run §22230889913 — Overall: PARTIAL

Core tests #1–10: ✅✅✅✅✅✅✅✅✅✅

PR review tests #11–17:

💥 [THE END] — Illustrated by Smoke Claude for issue #17206

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥 Automated smoke test review - all systems nominal!

💥 [THE END] — Illustrated by Smoke Claude for issue #17206

@pelikhan
Copy link
Contributor

@copilot add a shim.cjs for the core logging function and load this shim in the safe output server and safe input server.

update server.sh to copy shim.cjs in both folders

@github-actions
Copy link
Contributor

🤖 Smoke test 22233329073 results for @app/copilot-swe-agent:

Test
GitHub MCP
Safe Inputs GH CLI
Serena MCP
Playwright
File Writing
Bash Tool
Discussion Interaction
Build gh-aw
Discussion Creation
Workflow Dispatch
PR Review

Overall: ⚠️ PARTIAL PASS (10/11) — Serena MCP not available

📰 BREAKING: Report filed by Smoke Copilot for issue #17206

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed PR #17206 — the fix properly handles the missing origin/(branch) ref during push_to_pull_request_branch patch generation. The resolveBaseRef fallback chain is solid and the migration from shell to JS is clean.

📰 BREAKING: Report filed by Smoke Copilot for issue #17206

const { getErrorMessage } = require("./error_helpers.cjs");
const { execGitSync } = require("./git_helpers.cjs");

const PATCH_PATH = "/tmp/gh-aw/aw.patch";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to extract PATCH_PATH as a named constant — makes it easy to change the path in one place if needed.

const baseRef = `origin/${branchName}`;
core.info(`[generate_git_patch] using remote tracking ref as baseRef="${baseRef}"`);
return baseRef;
} catch {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three-level fallback strategy in resolveBaseRef (remote tracking ref → fresh fetch → merge-base) is well-structured and covers the gh pr checkout edge case nicely.

@github-actions
Copy link
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

Smoke test complete: 10/11 tests passed. Serena MCP unavailable. Labels not added (not all tests passed).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect patch generation on follow-up issue_comment runs for push_to_pull_request_branch by ensuring the remote base ref is fetched (instead of immediately falling back to merge-base), and adds a Node shim so scripts relying on GitHub Actions’ core global can run in MCP server contexts.

Changes:

  • Refactors generate_git_patch.cjs into helpers and fetches origin/<branch> when the tracking ref is missing to avoid including already-applied commits.
  • Introduces shim.cjs and loads it early in MCP server entrypoints; updates tests to mock global.core.
  • Removes the legacy shell patch generator and a Go test that depended on it; updates setup docs and file-copy lists.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
actions/setup/js/generate_git_patch.cjs Fetches missing remote branch tracking ref before computing patch base; refactors patch generation into helpers with added logging.
actions/setup/js/generate_git_patch.test.cjs Adds global.core mock and clears mocks between tests.
actions/setup/js/shim.cjs Adds a minimal global.core shim for non-GitHub Actions Node execution.
actions/setup/js/safe-outputs-mcp-server.cjs Requires the shim first so global.core exists before other imports.
actions/setup/js/safe_inputs_mcp_server_http.cjs Requires the shim first so global.core exists before other imports.
actions/setup/js/safe_outputs_handlers.test.cjs Adds global.core mock and clears mocks between tests.
actions/setup/setup.sh Ensures shim.cjs is copied into both safe-inputs and safe-outputs deploy directories.
actions/setup/README.md Updates shell script count/list after removing generate_git_patch.sh.
actions/setup/sh/generate_git_patch.sh Deleted (superseded by JS implementation).
pkg/workflow/git_patch_head_test.go Deleted (was testing the removed shell script path).
.changeset/patch-fetch-push-patch-base.md Changeset entry for the patch-base fetch behavior change.
.changeset/smoke-test-push-22232216256.md Adds a smoke-test artifact file (currently malformed content).
Comments suppressed due to low confidence (1)

actions/setup/js/generate_git_patch.cjs:40

  • The new “missing tracking ref → fetch origin/ → fallback” logic is the core fix for follow-up issue_comment runs, but there’s no test exercising this path (e.g., simulating a repo where refs/remotes/origin/<branch> is absent after gh pr checkout). Adding a focused integration-style unit test around resolveBaseRef/tryBranchStrategy would help prevent regressions.
function resolveBaseRef(branchName, defaultBranch, cwd) {
  try {
    execGitSync(["show-ref", "--verify", "--quiet", `refs/remotes/origin/${branchName}`], { cwd });
    const baseRef = `origin/${branchName}`;
    core.info(`[generate_git_patch] using remote tracking ref as baseRef="${baseRef}"`);
    return baseRef;
  } catch {
    // Remote tracking ref not found (e.g. after gh pr checkout which doesn't set tracking refs).
    // Try fetching the branch from origin so we use only the NEW commits as the patch base.
    core.info(`[generate_git_patch] refs/remotes/origin/${branchName} not found; fetching from origin`);
  }

  try {
    execGitSync(["fetch", "origin", branchName], { cwd });
    const baseRef = `origin/${branchName}`;
    core.info(`[generate_git_patch] fetch succeeded, baseRef="${baseRef}"`);
    return baseRef;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 20, 2026

@copilot fix tests to use shims https://github.com/github/gh-aw/actions/runs/22233320203/job/64318520951?pr=17206

Fixed in 5ff8086. The TypeScript typecheck was failing because global.core is not declared on typeof globalThis. Added @ts-expect-error comments on both the check and the assignment in shim.cjs, matching the pattern used in setup_globals.cjs.

@github-actions
Copy link
Contributor

Smoke Test Results — Run §22233329042

Overall: PARTIAL (17/17 run, 1 skipped)

Core: ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ (#1–10 all pass)
PR Review: ✅ ✅ ✅ ✅ ✅ ✅ ⚠️ (#11–16 pass, #17 skipped — no safe PR to close)

💥 [THE END] — Illustrated by Smoke Claude for issue #17206

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥 Automated smoke test review - all systems nominal!

💥 [THE END] — Illustrated by Smoke Claude for issue #17206

pelikhan and others added 5 commits February 20, 2026 11:49
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pelikhan pelikhan added the smoke label Feb 21, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 21, 2026

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

@github-actions
Copy link
Contributor

📰 BREAKING: Smoke Copilot is now investigating this pull request. Sources say the story is developing...

@github-actions
Copy link
Contributor

github-actions bot commented Feb 21, 2026

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

@github-actions
Copy link
Contributor

Smoke test §22246618529 results for @pelikhan:

Test
GitHub MCP
Safe Inputs GH CLI
Serena MCP
Playwright
File Writing + Bash
Discussion Interaction
Build gh-aw
Discussion Creation
Workflow Dispatch
PR Review

Overall: PASS (Serena MCP not available in this env)

📰 BREAKING: Report filed by Smoke Copilot

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick review of PR #17206. The core fix — fetching origin/(branch) before generating the patch — is solid and well-structured with a clear fallback chain. Two minor observations: (1) duplicate changeset files, and (2) hardcoded PATCH_PATH. Overall the logic is correct and well-commented.

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions
Copy link
Contributor

PR titles:

  • Copilot/update smoke labels
  • [docs] docs: remove bloat from network.md (21% line reduction)
    GitHub MCP: ✅
    Serena MCP: ✅
    Playwright: ✅
    File write+verify: ✅
    Build (make build): ✅
    Overall: PASS

🔮 The oracle has spoken through Smoke Codex

@pelikhan pelikhan closed this Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants